import { useRef } from 'react';
export const usePropsChecker = process.env.NODE_ENV !== 'development' ?
  (name: string, props: any, disabled?: boolean) => void 0 :
  (name: string, props: any, disabled?: boolean) => {
    const c_k = disabled ? [] : Object.keys(props).sort();
    const c_v = disabled ? [] : c_k.map(k => props[k]);

    const p_k = useRef(c_k);
    const p_v = useRef(c_v);

    if (p_k.current.length !== c_k.length) {
      console.warn(
        '[PropsChecker]', name, ' props.length changed,',
        'prev keys:', p_k, 'current keys:', c_k
      );
    } else {
      let i = 0;
      for (; i < c_k.length; ++i) {
        if (c_k[i] !== p_k.current[i])
          break;
      }
      if (i < c_k.length) {
        console.log(
          '[PropsChecker]', name, ' props key changed,',
          ' prev:', p_k.current[i], 'curr:', c_k[i]
        );
      } else {
        const ii = [];
        for (let i = 0; i < c_v.length; ++i)
          (c_v[i] !== p_v.current[i]) && ii.push(i);

        if (ii.length) {
          console.group(
            `[PropsChecker]${name} props changed.`,
            ...ii.map(i => [c_k[i], p_v.current[i], c_v[i]])
          );
          console.groupEnd();
        }
      }
    }

    p_k.current = c_k;
    p_v.current = c_v;
  }
